package cn.myzqu.start.lambda;

import cn.myzqu.start.lambda.entity.Student;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class ForEachMap {

    public static void main(String[] args) {

        Student student1 = new Student("Lin", 18);
        Student student2 = new Student("的川", 17);
        List<Student> studentList = new ArrayList<>();
        studentList.add(student1);
        studentList.add(student2);
        Map<String, Student> studentExtMap =
                studentList.stream().collect(Collectors.toMap(s -> s.getName(), Function.identity()));
        //Map遍历
        studentExtMap.forEach((key, value) -> System.out.println(key + ":" + value.getAge()));
        //修改
        studentExtMap.forEach((key, value) -> {
            if (key.equals("的川")) {
                studentExtMap.remove(key);
            }
        });
        studentExtMap.forEach((key, value) -> System.out.println(key + ":" + value.getName()));
    }

}



